package com.cgbl.cg.view

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cgbl.cg.R
import com.cgbl.cg.adapter.CouponAdapter
import com.cgbl.cg.adapter.JobAdapter
import com.cgbl.cg.adapter.SelectCouponAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.lxj.xpopup.core.BottomPopupView
import com.robot.base.model.CouponBean

class SelectCouponPop(context: Context) : BottomPopupView(context) {

    lateinit var couponList: RecyclerView

    var couponAdapter: SelectCouponAdapter = SelectCouponAdapter()

    var listener: ((CouponBean) -> Unit)? = null

    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_select_coupon
    }

    override fun initPopupContent() {
        super.initPopupContent()
        couponList = findViewById(R.id.job_list)
        couponList.layoutManager = LinearLayoutManager(context)
        couponList.adapter = couponAdapter
        couponAdapter.setOnItemClickListener { _, _, position ->
            this.listener?.invoke(couponAdapter.getItem(position))
            dismiss()
        }
    }

    fun setOnSelectCouponListener(listener: ((CouponBean) -> Unit)?) {
        this.listener = listener
    }
}